#include "common/pch.h"

#include <cftc/reflect/class.h>
#include <cftc/reflect/field.h>

#include "object/local_transport.h"

namespace battle::object
{

    LocalTransport::LocalTransport() : Transport()
    {
    }

    LocalTransport::~LocalTransport()
    {
        //sLog.outString("Deleting %s, map %u", GetGuidStr().c_str(), GetMap()->GetId());
    }

    bool LocalTransport::Initialize(unsigned int guid, Map* m)
    {
#if 0
        if (m == NULL)
        {
            return false;
        }

        GameObjectData const* gdata = sObjectMgr.GetGOData(guid);
        if (!gdata)
        {
            sLog.outErrorDb("Local transport GUID %u does not exist into `gameobject` table", guid);
            return false;
        }

        GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(gdata->id);
        if (goinfo->type != GAMEOBJECT_TYPE_TRANSPORT)
        {
            sLog.outErrorDb("Local transport GUID:%u, Name:%s, Entry:%u  will not be loaded, `gameobject_template` type record is wrong", guid, goinfo->name, goinfo->id);
            return false;
        }

        Object::_Create(guid, goinfo->id, HIGHGUID_TRANSPORT);

        float r0, r1, r2, r3;
        r0 = gdata->rotation0;
        r1 = gdata->rotation1;
        r2 = gdata->rotation2;
        r3 = gdata->rotation3;

        if (r0 == 0.0f && r1 == 0.0f && r2 == 0.0f)      //TODO make a method for this
        {
            r2 = sin(gdata->orientation / 2);
            r3 = cos(gdata->orientation / 2);
        }

        G3D::Quat q(r0, r1, r2, r3);
        q.unitize();

        float o = GetOrientationFromQuat(q);
        SetMap(m);
        Relocate(gdata->posX, gdata->posY, gdata->posZ, o);

        if (!IsPositionValid())
        {
            sLog.outError("Local transport GUID:%u, Name:%s, Entry:%u not created. Suggested coordinates are not valid: (X, Y, Z)=(%f, %f, %f)",
                guid, goinfo->name, goinfo->id, gdata->posX, gdata->posY, gdata->posZ);
            return false;
        }

        SetQuaternion(q);
        SetGOInfo(goinfo);
        SetObjectScale(goinfo->size);
        SetGoType(GAMEOBJECT_TYPE_TRANSPORT);
        SetEntry(goinfo->id);

        SetFloatValue(GAMEOBJECT_POS_X, gdata->posX);
        SetFloatValue(GAMEOBJECT_POS_Y, gdata->posY);
        SetFloatValue(GAMEOBJECT_POS_Z, gdata->posZ);
        Setunsigned intValue(GAMEOBJECT_FACTION, goinfo->faction);
        Setunsigned intValue(GAMEOBJECT_FLAGS, goinfo->flags);
        Setunsigned intValue(GAMEOBJECT_DISPLAYID, goinfo->displayId);

        SetGoState(GO_STATE_READY);
        SetGoAnimProgress(GO_ANIMPROGRESS_DEFAULT);
        SetName(goinfo->name);
#endif
        return true;
    }

}